package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.period.PeriodDayDto;
import com.cxx.home.dto.period.PeriodSettingDto;
import com.cxx.home.service.PeriodService;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/period")
@Tag(name = "月经记录")
public class PeriodController {
    @Resource
    private PeriodService periodService;

    @Operation(summary = "查询月经天")
    @GetMapping("/day")
    public @JsonView(ReadView.class) List<PeriodDayDto> queryPeriodDay(@RequestParam("month") String month) {
        return periodService.queryPeriodDay(month);
    }

    @Operation(summary = "更新月经天")
    @PutMapping("/day/{id}")
    public Boolean updatePeriodDay(@PathVariable("id") long id,
                                   @RequestBody @JsonView(WriteView.class) PeriodDayDto periodDayDto) {
        return periodService.updatePeriodDay(id, periodDayDto);
    }

    @Operation(summary = "获取当月月经初始天")
    @GetMapping("/menstruate")
    public String getMenstruateFirstDate(@RequestParam("month") String month) {
        return periodService.getMenstruateFirstDate(month);
    }

    @Operation(summary = "查询月经设置")
    @GetMapping("/setting")
    public @JsonView(ReadView.class) PeriodSettingDto queryPeriodSetting() {
        return periodService.queryPeriodSetting();
    }

    @Operation(summary = "更新月经设置")
    @PutMapping("/setting/{id}")
    public Boolean updatePeriodSetting(@PathVariable("id") long id,
                                       @RequestBody @JsonView(WriteView.class) PeriodSettingDto periodSettingDto) {
        return periodService.updatePeriodSetting(id, periodSettingDto);
    }
}
    